package com.isoft.c2team3service2.controller;

import com.isoft.c2team3service2.bean.ResponseData;
import com.isoft.c2team3service2.common.Result;
import com.isoft.c2team3service2.entity.Person;
import com.isoft.c2team3service2.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/insert")
public class PersonController extends BaseController{
    @Autowired
    PersonService personService;

    @PostMapping("/add")
    public ResponseData<Boolean> insert(String username,String birthdate,
                                        String phonenumber , String nick_name,
                                        String email ,Integer login_id ){
        //判空
        if (username == null || birthdate == null
                || phonenumber == null || nick_name == null
                || email == null || login_id == null){
            return resultBoolean(false,"添加");
        }
        boolean b = personService.insertPerson(username,birthdate,phonenumber,nick_name , email,login_id);
        return resultBoolean(b,"添加");

    }

    //根据邮箱查询
    @GetMapping("/select")
    public ResponseData<Person>get( String email){
        return resultT(personService.updatePerson(email),"根据邮箱查询");
    }

    //根据id查询
    @GetMapping("/getById")
    public Result<Person> getById(Integer id){
        return Result.success(personService.selectById(id));
    }
}
